public class Test4 {
    public static void main(String[] args) {
        String string = "Hello, my       name is John";
        if(string == null){
            System.out.println(0);
        }
        if(string.length() == 0){//string.isEmpty()
            System.out.println(0);
        }
        String[] strings = string.split(" ");
        int len = strings.length;
        for (int i = 0; i < strings.length; i++) {
            if (strings[i].length() == 0){
                len--;
            }
        }
        System.out.println(len);
    }
}
